home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 6.0 KB | 235 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UContainer.cp
- // Copyright © 1995-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
-
-
- #ifndef __UCONTAINER__
- #include "UContainer.h"
- #endif
-
- #if qContainer
-
- // MacApp
-
- // For CALib we have to break the encapsulation of TWindow and TDocument
- // so we can find its CADocumentRef.
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // CALib
-
- #ifndef _CALIB_
- #include "CALib.h"
- #endif
-
- // Toolbox
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- //========================================================================================
- // Global Variables
- //========================================================================================
-
- Boolean gContainerLib;
-
- //========================================================================================
- // Global Functions
- //========================================================================================
-
- static void MARegisterMenu(CACommandID id, CommandNumber number);
- static void MARegisterCommand(CACommandID id, CommandNumber number);
-
- //----------------------------------------------------------------------------------------
- // HasContainerLib:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- Boolean HasContainerLib()
- {
- #if qContainer
- static Boolean defined = FALSE;
- static Boolean hasContainerLib;
- if (!defined)
- {
- defined = TRUE;
- hasContainerLib = ((Ptr)CAInit != (Ptr)kUnresolvedCFragSymbolAddress);
- }
- return hasContainerLib;
- #else
- return FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // InstallContainerLib
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void InstallContainerLib()
- {
- if (HasContainerLib())
- {
- OSErr theErr;
-
- CAInit(); // Initialize CALib
- if ((theErr = CAError()) != noErr) return;
-
- #if 0 // $$$$$ temporary until implementation is back in CALib
- CAInstallFloatingWindowHandlers(MA_CAFrontWindowProc, MASelectToolboxWindow,
- IsFloatWindow);
- if ((theErr = CAError()) != noErr) return;
- #endif
-
- gContainerLib = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MA_CAFrontWindowProc
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- WindowPtr MA_CAFrontWindowProc(CAWindowLayer windowLayer)
- {
- switch (windowLayer)
- {
- case kCADocumentWindow:
- return TWindow::MAFrontWindow();
-
- case kCAFloatingWindow:
- return TWindow::GetFirstFloatingWindowPtr();
-
- default:
- break;
- }
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // GetCADocument
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- CADocumentRef GetCADocument(WindowPtr wMgrWindow)
- {
- CADocumentRef containerDocument = NULL;
- if (wMgrWindow)
- {
- TWindow* window = TWindow::WMgrToWindow(wMgrWindow);
- if (window)
- containerDocument = GetCADocument(window);
- }
- return containerDocument;
- }
-
- CADocumentRef GetCADocument(TWindow* window)
- {
- CADocumentRef containerDocument = NULL;
- if (window)
- {
- TDocument* windowDocument = window->fDocument;
- if (windowDocument)
- containerDocument = windowDocument->GetContainer();
- }
- return containerDocument;
- }
-
- //========================================================================================
- // CLASS CModalFocus
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CModalFocus::CModalFocus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- CModalFocus::CModalFocus(WindowPtr window)
- : fWindow(window), fHasFocus(FALSE)
- {
- // Setup the FailInfo to catch any failures while this object is in scope
- fFailInfo.SetCleanupProc(CModalFocus::CallRelinquish, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CModalFocus::~CModalFocus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- CModalFocus::~CModalFocus()
- {
- FailOSErr(this->Relinquish());
- fFailInfo.Success();
- }
-
- //----------------------------------------------------------------------------------------
- // CModalFocus::Request:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean CModalFocus::Request()
- {
- Boolean result = FALSE;
- if (fWindow)
- {
- if (gContainerLib)
- result = fHasFocus = CARequestModalFocus(fWindow);
- else
- result = TRUE;
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CModalFocus::Relinquish:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- OSErr CModalFocus::Relinquish()
- {
- OSErr err = noErr;
- if (gContainerLib && fWindow && fHasFocus)
- {
- CARelinquishModalFocus(fWindow);
- fHasFocus = FALSE;
- err = CAError();
- }
- return err;
- }
-
- //----------------------------------------------------------------------------------------
- // CModalFocus::CallRelinquish:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void CModalFocus::CallRelinquish(void* context)
- {
- ((CModalFocus*) context)->Relinquish();
- }
-
- //----------------------------------------------------------------------------------------
- // End of UContainer.cp
-
- #endif // qContainer
-